cmake_minimum_required(VERSION 2.6)

project(SkyX)

set(CMAKE_DEBUG_POSTFIX "_d")

if (MSVC)
  add_definitions(/fp:fast)
endif ()

if (CMAKE_COMPILER_IS_GNUCXX)
  # Test for GCC visibility
  include(CheckCXXCompilerFlag)
  check_cxx_compiler_flag(-fvisibility=hidden SKYX_GCC_VISIBILITY)
  if (OGRE_GCC_VISIBILITY)
    # determine gcc version
    execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
      OUTPUT_VARIABLE SKYX_GCC_VERSION
    )
    message(STATUS "Detected g++ ${SKYX_GCC_VERSION}")
    message(STATUS "Enabling GCC visibility flags")
    set(SKYX_GCC_VISIBILITY_FLAGS "-DSKYX_GCC_VISIBILITY -fvisibility=hidden")

    # check if we can safely add -fvisibility-inlines-hidden
    string(TOLOWER "${CMAKE_BUILD_TYPE}" SKYX_BUILD_TYPE)
    if (SKYX_BUILD_TYPE STREQUAL "debug" AND SKYX_GCC_VERSION VERSION_LESS "4.2")
      message(STATUS "Skipping -fvisibility-inlines-hidden due to possible bug in g++ < 4.2")
    else ()
      set(SKYX_GCC_VISIBILITY_FLAGS "${SKYX_GCC_VISIBILITY_FLAGS} -fvisibility-inlines-hidden")
    endif ()
  endif (OGRE_GCC_VISIBILITY)

  # Fix x64 issues on Linux
  if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE)
    add_definitions(-fPIC)
  endif()
endif (CMAKE_COMPILER_IS_GNUCXX)

add_subdirectory(SkyX)
